package com.qbccn.bbs.controller;

import com.qbccn.bbs.domain.BbsUser;
import com.qbccn.bbs.service.PageService;
import com.qbccn.bbs.service.UserService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author linke
 * @date 2020/5/30 20:27
 * @description
 */
@Controller
public class PageController {

  @Autowired
  private HttpServletRequest request;
  @Autowired
  private UserService userService;
  @Autowired
  private PageService pageService;

  @GetMapping("")
  public String index() {
    Object user = request.getSession().getAttribute("user");
    if (user != null) {
      BbsUser u = (BbsUser) user;
      //是否签到了
      boolean signStatus = userService.signStatus(u.getUsername());
      request.setAttribute("signStatus", signStatus);
      //连续签到的天数
      request.setAttribute("lx", userService.getLXSignDayNumber());
    } else {
      request.setAttribute("signStatus", false);
    }
    request.setAttribute("aclass",pageService.getArticleClass());
    return "index";
  }

  @GetMapping("login")
  public String login() {
    return "user/login";
  }

  @GetMapping("register")
  public String register() {
    return "user/register";
  }
}
